import { defineStore } from "pinia";
import { useStorage } from "@vueuse/core";
// import defaultSettings from "@/settings";
import { store } from "@/store";
import en from "element-plus/es/locale/lang/en";
import zhCn from "element-plus/es/locale/lang/zh-cn";

// setup mode
export const useAppStore = defineStore("app", () => {
  //   const language = useStorage("language", defaultSettings.language);
  const language = useStorage("language", "zh-cn");

  // 根据语言标识读取对应的语言包
  const locale = computed(() => {
    if (language?.value == "en") {
      return en;
    } else {
      return zhCn;
    }
  });

  //   切换语言
  function changeLanguage(val: string) {
    language.value = val;
  }

  return {
    language,
    locale,
    changeLanguage,
  };
});

// 如何在组件外使用store
export function useAppStoreHook() {
  return useAppStore(store);
}
